package pl.edu.mimuw.mas.agent.gui.common;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import java.awt.Component;

/**
 * Wyświetlanie kolorów w GUI.
 */
public class ColorRenderer extends JLabel implements TableCellRenderer {
	private static final long serialVersionUID = -4334642463287845853L;

	private Border unselectedBorder = null;
	private Border selectedBorder = null;

	public ColorRenderer() {
		setOpaque(true);
	}

	public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) {
		Color col = (Color) color;
		setBackground(col);

		if (isSelected) {
			selectedBorder = BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground());
			setBorder(selectedBorder);
		} else {
			unselectedBorder = BorderFactory.createMatteBorder(1, 1, 1, 1, table.getBackground());
			setBorder(unselectedBorder);
		}

		return this;
	}
}
